/*
 * Auto Login Extension or ALEx, allows you to easily log in on websites
 * with tiresome security systems, such as banks.  
 * Copyright (C) 2012 Bruno Macherel, Pierre-Marie Dhaussy, Aurélie Gandour
 * <auto-login-extension@googlegroups.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  See LICENSE.txt or <http://www.gnu.org/licenses/  >.
 */

////////////////////////////////////////////////////////////////////////////////
// Must be redefined for each browser
////////////////////////////////////////////////////////////////////////////////
Settings.prototype._load = function(name, callback) {
/*
	if(!name) {
		// Build preferences from localStorage
		for(var i=0; i<localStorage.length; i++) {
			var key = localStorage.key(i);
			this._load(key, callback);
		}
	} else {
		callback(name, this.__load(name));
	}
*/
	callback(name, this.__load(name));
}
Settings.prototype.__load = function(name) {
	if(!name) {
		var settings = {};
		// Build preferences from localStorage
		for(var i=0; i<localStorage.length; i++) {
			var key = localStorage.key(i);
			settings[key] = this.__load(key);
		}
		return settings;
	} else {
		return JSON.parse(window.localStorage.getItem(name));
	}
}
Settings.prototype._store = function(value, name) {
	if(!name) {
		if(value instanceof Object) {
			for(var key in value) {
				this._store(value[key], key);
			}
		}
	} else {
		window.localStorage.setItem(name, JSON.stringify(value));
	}
}

////////////////////////////////////////////////////////////////////////////////
// browser specific
////////////////////////////////////////////////////////////////////////////////
